// 添加课程
<template>
  <div id="bcjh-add-course">
    <el-row style="width: calc(100% - 20px);overflow: hidden;">
      <el-col :span="4">
          <el-tree
              default-expand-all
              :data="data"
              :props="defaultProps"
              @node-click="handleNodeClick"
              style="color: #004ca7;margin: 20px 40px;"
            ></el-tree>
      </el-col>
      <el-col :span="20" class="border-left">
        <div class="assessment-container">
            <div class="search-container">
      <div class="search-container-left">
        <div class="search-container-item">
          <span>课程编号：</span>
          <el-input
            style="width: 152px"
            size="mini"
            placeholder="请输入内容"
            v-model="courseNum"
          ></el-input>
        </div>
        <div class="search-container-item">
          <span>课程名称：</span>
          <el-input
            style="width: 152px"
            size="mini"
            placeholder="请输入内容"
            v-model="courseName"
          ></el-input>
        </div>
         <div class="search-button" @click="getCourse">
          <img src="../../../../assets/assessment/icon-search.png" alt="" />
          <span>查询</span>
        </div>
      </div>
    </div>
          <div class="table-container">
            <el-table
              :data="tableData"
              border
              class="table-data"
              row-class-name="row-class"
              cell-class-name="cell-class"
              header-row-class-name="header-row-class"
              header-cell-class-name="header-cell-class"
              style="height: calc(100vh - 400px); overflow-y: auto"
              @selection-change="handleSelectionChange"
              :row-key="getRowKeys"
            >
            <el-table-column align="center" :reserve-selection="true" type="selection" width="80"></el-table-column>
              <el-table-column prop="courseCode" label="课程编号" align="center"></el-table-column>
              <el-table-column prop="courseName" label="课程名称" align="center"></el-table-column>
              <el-table-column prop="courseSimpleName" label="简称" align="center"></el-table-column>
              <el-table-column prop="credit" label="学分" align="center"></el-table-column>
              <el-table-column prop="totalHours" label="总学分" align="center"></el-table-column>
              <el-table-column prop="eduLevel" label="通用培养层次" align="center"></el-table-column>
              <el-table-column prop="mainSubject" label="是否主干课" align="center"></el-table-column>
              <el-table-column prop="remark" label="备注" align="center"></el-table-column>
            </el-table>
          </div>
        </div>
        <div class="bottom-block" style="display: block">
      <div class="text">
        当前共找到{{ total }}条记录,当前显示{{ startPage }}-{{ endPage }}条
      </div>
      <!-- <div class="export-button">
        <img src="../../../../assets/assessment/icon-export.png" alt="" />
        <download-excel
            class="export-btn"
            :data="tableData"
            :fields="jsonFields"
            type="xls"
            name="课程列表.xls"
            style="color: #f3b815"
          >
            &ensp;导出Excel
          </download-excel>
      </div> -->
    </div>
    <div class="pagination-block">
      <el-pagination
        prev-text="上一页"
        next-text="下一页"
        :page-size="pageSize"
        layout="prev, pager, next, jumper"
        :total="total"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
      >
      </el-pagination>
    </div>
        <div class="btn-caozuo">
          <el-button type="warning" @click="saveAddCourse" size="mini">保存</el-button>
          <el-button type="danger" @click="cancelAddCourse" size="mini">取消</el-button>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import tablelist from "@/views/comonents/tablelist";
import ButtonItem from "@/components/ButtonItem.vue";

import {getCourse,  addZxjhCourse, queryCommonJysDept,} from "@/api/trainingManagement/place.js";

export default {
  components: {
    tablelist,
    ButtonItem,
  },
  data() {
    return {
      total: 0, //总条数
      pageSize: 50, //条数
      startPage: 0, //开始条数
      endPage: 0, //结束条数
      currentPage: 1, //当前页数
      jsonFields:{
        '课程编号': 'courseCode',
        '课程名称': 'courseName',
        '简称': 'courseSimpleName',
        '学分': 'credit',
        '总学分': 'totalHours',
        '通用培养层次': 'eduLevel',
        '是否主干课': 'mainSubject',
        '备注':'remark'
      },
      courseNum: "", //课程编号
      courseName: "", //课程名称
        // 校区列表
      data: [],
      defaultProps: {
        children: "children",
        label: "name",
      },
      tableData: [],
      typeList: [{ label: "全部", value: "全部" }],
      selectTreeInfo: {}, //点击树节点
      selectTreeNode: {},
      selectCourseList: [], //选择课程列表
      kcId: "", //专业班次id
      xueqi: "", //学期
    };
  },
  created() {},
  mounted() {
    this.kcId = this.$route.query.kcId;
    this.xueqi = this.$route.query.xueqi;
    this.queryCommonDept();
  },
  methods: {
    getRowKeys(row) {
      return row.id
    },
    async queryCommonDept() {
      const res = await queryCommonJysDept();
      if (res.data.code == 200) {
        this.data = res.data.data;
        this.selectTreeInfo = this.data[0];
        this.getCourse();
      }
    },
    handleSelectionChange(val) {
      this.selectCourseList = val;
    },
    // 添加课程
    async saveAddCourse() {
      if (this.selectCourseList.length > 0) {
        var list = [];
        this.selectCourseList.forEach(item => {
          list.push( {courseId: item.id})
        })
        var params = {
          "zybcId": this.kcId,
          "xueqi": this.xueqi,
          "kcList":list
        }
        const res = await addZxjhCourse(params);
        if (res.data.code == 200) {
          this.$message.success("课程保存成功！");
          this.cancelAddCourse();
        }
      } else {
        this.$message.warning("请先选择你要添加的课程!");
      }

    },
    // 取消添加课程
    cancelAddCourse() {
      var id = this.kcId;
      var xq = this.xueqi
      this.$router.push({
        path: "/admin/teachingTaskManage/profCourse",
        query: {
          id: id,
          xq: xq
        }
      });
    },
    handleNodeClick(data, node) {
      this.selectTreeInfo = data;
      this.selectTreeNode = node;
      this.getCourse()
    },
    // 获取课程数据
    async getCourse() {
      var teachingClassName = this.selectTreeNode.level == 2 ? this.selectTreeInfo.id || '' : '';
      var bx = this.selectTreeNode.level == 1 ? this.selectTreeInfo.name :'';
      var courseName = this.courseName;
      var courseCode = this.courseNum;
      var current= this.currentPage;
      var size = this.pageSize;
      // teachingClassName="教研室1";
      // bx="基础教学系";
      // courseName="测试课程"
      const res = await getCourse(teachingClassName, bx, courseName, courseCode, current, size);
      if (res.data.code == 200) {
        this.tableData = res.data.data.records;
        this.total = res.data.data.total;
        var length = this.tableData.length;
        this.calculatePage(
          this.pageSize,
          res.data.data.current, length);
      } else {
        this.$message.warning("数据查询失败!");
      }
    },
     // 计算开始和结束条数
    calculatePage(pageSize, current, length) {
      if (current == 1) {
        if (length != 0) {
          this.startPage = 1;
          this.endPage = length;
        }
      } else {
        this.startPage = pageSize * (current - 1) + 1;
        this.endPage = parseInt(this.startPage)  + parseInt(length) - 1;
      }
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getCourse();
    },
  },
  computed: {}, //计算属性
};
</script>

<style lang="less" scoped>
.choose-ypr-container {
  width: 767px;
  margin: 0px auto;
  .choose-ypr-search-container {
    .el-input--prefix .el-input__inner {
      padding-left: 30px;
    }
    .el-input__inner {
      &::placeholder {
        color: #b8b8b8;
      }
      &::-webkit-input-placeholder {
        /* WebKit browsers 适配谷歌 */
        color: #b8b8b8;
      }
      &:-moz-placeholder {
        /* Mozilla Firefox 4 to 18 适配火狐 */
        color: #b8b8b8;
      }
      &::-moz-placeholder {
        /* Mozilla Firefox 19+ 适配火狐 */
        color: #b8b8b8;
      }
      &:-ms-input-placeholder {
        /* Internet Explorer 10+  适配ie*/
        color: #b8b8b8;
      }
    }
    display: flex;
    flex-direction: row;
    align-items: center;
    .title {
      font-size: 18px;
      font-family: Microsoft YaHei;
      font-weight: bold;
      line-height: 20px;
      color: #004ca7;
      margin-right: 5px;
    }
    .search-button {
      width: 77px;
      height: 28px;
      line-height: 28px;
      background: #f1f8fe;
      border: 1px solid #51aef6;
      border-radius: 6px;
      cursor: pointer;
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: center;
      > span {
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #51aef6;
      }
      > img {
        width: 20px;
        height: 20px;
        margin-right: 4px;
      }
    }
    .button-list {
      display: flex;
      flex-direction: row;
      align-items: center;
      margin-left: 21px;
      .button-item {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        position: relative;
        width: 69px;
        height: 27px;
        line-height: 27px;
        border: 1px solid #004ca7;
        border-radius: 4px;
        margin-right: 10px;
        text-align: center;
        font-size: 14px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #004ca7;
        .del-icon {
          position: absolute;
          right: 0px;
          top: 0px;
          width: 12px;
          height: 12px;
          padding: 2px;
        }
      }
    }
  }
  .choose-ypr-table-container {
    margin-top: 30px;
    .el-table td,
    .el-table th.is-leaf,
    .el-table--border,
    .el-table--group {
      border-color: #c7d7eb;
    }
    .el-table__header tr,
    .el-table__header th {
      padding: 0;
      height: 57px;
      background-color: #edf2f9;
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: bold;
      line-height: 20px;
      color: #004ca7;
    }
    .el-table__body tr,
    .el-table__body td {
      padding: 0;
      height: 51px;
    }
    .table-data {
      width: 100%;
      border: 0.8px solid #004ca7;
      /*border-radius: 9px;*/
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #004ca7;
    }
  }
}
.assessment-container {
    width: 100%;
  .el-dialog__body {
    height: 251px;
  }
  .el-dialog__footer {
    padding: 10px 20px 45px;
  }
  .el-checkbox__inner:hover {
    border-color: #004ca7;
  }
  .el-checkbox__inner {
    border: 1px solid #004ca7;
    border-radius: 0;
    height: 18px;
    width: 18px;
  }
  .el-checkbox__inner::after {
    height: 10px;
    left: 6px;
  }
  .el-checkbox__input.is-checked .el-checkbox__inner,
  .el-checkbox__input.is-indeterminate .el-checkbox__inner {
    background-color: #004ca7;
    border-color: #004ca7;
  }
  .el-checkbox__input.is-checked + .el-checkbox__label {
    color: #004ca7;
  }
  .el-checkbox.is-bordered.is-checked {
    border-color: #004ca7;
  }
  .el-checkbox__input.is-focus .el-checkbox__inner {
    border-color: #004ca7;
  }
}
</style>
<style lang="less" scoped>
@import "../../../../styles/text.less";
/deep/ .assessment-container {
    width: 100%;
}
.assessment-container .table-container {
  width: 100%;
}
// .assessment-container .table-container .table-header {
//   width: 1935px;
// }
// .assessment-container .table-container .table-body {
//   width: 1935px;
// }
/deep/ .szjky .el-dialog__body {
  height: 432px;
}
.message-container {
  > div {
    display: inline-block;
    &:nth-child(1) {
      padding-left: 111px;
      font-size: 20px;
      color: rgba(0, 76, 167, 1);
      font-weight: bold;
      vertical-align: top;
    }
    &:nth-child(2) {
    }
  }
}
</style>
<style lang="less" scoped>
@import "../../../../styles/supervision.less";

.wrapper-container {
  width: 1400px;
  margin: 0 auto;
}

/deep/ .table-container {
        width: 1300px;
  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    /*border-radius: 9px;*/
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}

.wrapper-container .search-container .search-container-left {
  flex-wrap: wrap;
  .search-container-item {
    width: 12%;
    margin-right: 0px;
    .box {
      > span {
        text-align: left;
      }
      display: flex;
      justify-content: space-evenly;
      margin-bottom: 20px;
      align-items: center;
    }
  }
}

/deep/.el-date-editor.el-input {
  width: 110px;
}
/deep/ .el-input--medium {
  width: 110px;
  .el-input__inner {
    height: 28px;
    width: 110px;
    padding: 0px 18px;
  }
}
/deep/ .el-table thead {
  color: #004ca7 !important;
}

.btn {
  margin-top: 271px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 271px;
  .submit {
    width: 84px;
    height: 27px;
    line-height: 8px;
  }
}
.bottom-block {
  // display: flex;
  flex-direction: row;
  justify-content: space-between !important;
  .export-button {
    cursor: pointer;
    width: 127px;
    height: 27px;
    background: #fff6ef;
    border: 1px solid #f3b815;
    border-radius: 4px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    margin-top: 14px;
    > img {
      width: 17px;
      height: 17px;
    }
    > span {
      margin-left: 12px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #f3b815;
    }
  }
  .text {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    line-height: 39px;
    color: #004ca7;
  }
}

.btn-caozuo {
  display: flex;
  align-items: center;
  justify-content: space-around;
  width: 500px;
  margin: 0 auto;
  padding-top: 30px;
}

.border-left {
        padding-left: 30px;
    border-left: 1px solid #004ca7;
}
/deep/ .el-tree-node__label {
        font-size: 17px;
    font-weight: bold;
}
/deep/ .el-tree-node__expand-icon {
    color: #004ca7;
}

// @import "../../../../styles/delayedExam.less";
.pagination-block {
  margin-top: 20px;
  display: flex;
  flex-direction: row;
  justify-content: center;
}
</style>

<style lang="less" scoped>
  #bcjh-add-course{
    /deep/ .el-button--warning{
      background: #FFF6EF;
      border-color: #F3B815;
      color: #F3B815;
      border-radius: 6px;
    }
    /deep/ .el-button--warning:focus, .el-button--warning:hover{
      color: #F3B815;
      background: #FFF6EF;
      border: 1px solid #F3B815;
      border-radius: 6px;
    }

    /deep/ .el-button--danger{
      background: #FFEFEF;
      border-color: #FF3819;
      color: #FF3819;
      border-radius: 6px;
    }

    /deep/ .el-button--danger:hover{
      background: #FFEFEF;
      border: 1px solid #FF3819;
      color: #FF3819;
      border-radius: 6px;
    }
  }
</style>
